/* 解决 el-input-number 设置 null 会出现默认值 0 的问题 */

<template>
  <el-input-number v-model="valueModel" v-bind="$attrs" v-on="$listeners" />
</template>

<script>
export default {
  name: 'SafeInputNumber',
  props: {
    value: {
      type: [Number, String],
      default: undefined,
    },
  },

  computed: {
    valueModel: {
      get() {
        return this.$isEmpty(this.value)
          ? undefined
          : this.value
      },
      set(newVal) {
        newVal === undefined
          ? this.$emit('input', null)
          : this.$emit('input', newVal)
      },
    }
  }
}
</script>
